package com.ruoyi.local.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.local.mapper.SysAppmenuMapper;
import com.ruoyi.local.domain.SysAppmenu;
import com.ruoyi.local.service.ISysAppmenuService;
import com.ruoyi.common.core.text.Convert;

/**
 * APP菜单权限Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-12-18
 */
@Service
public class SysAppmenuServiceImpl implements ISysAppmenuService 
{
    @Autowired
    private SysAppmenuMapper sysAppmenuMapper;

    /**
     * 查询APP菜单权限
     * 
     * @param menuId APP菜单权限ID
     * @return APP菜单权限
     */
    @Override
    public SysAppmenu selectSysAppmenuById(Long menuId)
    {
        return sysAppmenuMapper.selectSysAppmenuById(menuId);
    }

    /**
     * 查询APP菜单权限列表
     * 
     * @param sysAppmenu APP菜单权限
     * @return APP菜单权限
     */
    @Override
    public List<SysAppmenu> selectSysAppmenuList(SysAppmenu sysAppmenu)
    {
        return sysAppmenuMapper.selectSysAppmenuList(sysAppmenu);
    }

    /**
     * 新增APP菜单权限
     * 
     * @param sysAppmenu APP菜单权限
     * @return 结果
     */
    @Override
    public int insertSysAppmenu(SysAppmenu sysAppmenu)
    {
        sysAppmenu.setCreateTime(DateUtils.getNowDate());
        return sysAppmenuMapper.insertSysAppmenu(sysAppmenu);
    }

    /**
     * 修改APP菜单权限
     * 
     * @param sysAppmenu APP菜单权限
     * @return 结果
     */
    @Override
    public int updateSysAppmenu(SysAppmenu sysAppmenu)
    {
        sysAppmenu.setUpdateTime(DateUtils.getNowDate());
        return sysAppmenuMapper.updateSysAppmenu(sysAppmenu);
    }

    /**
     * 删除APP菜单权限对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteSysAppmenuByIds(String ids)
    {
        return sysAppmenuMapper.deleteSysAppmenuByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除APP菜单权限信息
     * 
     * @param menuId APP菜单权限ID
     * @return 结果
     */
    @Override
    public int deleteSysAppmenuById(Long menuId)
    {
        return sysAppmenuMapper.deleteSysAppmenuById(menuId);
    }

    /**
     * 查询APP菜单权限树列表
     * 
     * @return 所有APP菜单权限信息
     */
    @Override
    public List<Ztree> selectSysAppmenuTree()
    {
        List<SysAppmenu> sysAppmenuList = sysAppmenuMapper.selectSysAppmenuList(new SysAppmenu());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (SysAppmenu sysAppmenu : sysAppmenuList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(sysAppmenu.getMenuId());
            ztree.setpId(sysAppmenu.getParentId());
            ztree.setName(sysAppmenu.getMenuName());
            ztree.setTitle(sysAppmenu.getMenuName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
